package com.framework.modules.user.controller;

import java.util.Arrays;
import java.util.Map;

import com.framework.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.framework.modules.user.entity.UserBankEntity;
import com.framework.modules.user.service.UserBankService;
import com.framework.common.utils.PageUtils;
import com.framework.common.utils.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 用户银行表 
 *
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-11-10 12:48:04
 */
@RestController
@RequestMapping("user/userbank")
@Api(tags = "UserBankController")
public class UserBankController {
    @Autowired
    private UserBankService userBankService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("user:userbank:list")
    @ApiOperation("list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = userBankService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("user:userbank:info")
    @ApiOperation("info")
    public R info(@PathVariable("id") Integer id) {
        UserBankEntity userBank = userBankService.selectById(id);

        return R.ok().put("userBank", userBank);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("user:userbank:save")
    @ApiOperation("save")
    public R save(@RequestBody UserBankEntity userBank) {
        userBankService.insert(userBank);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("user:userbank:update")
    @ApiOperation("update")
    public R update(@RequestBody UserBankEntity userBank) {
        ValidatorUtils.validateEntity(userBank);
        userBankService.updateAllColumnById(userBank);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("user:userbank:delete")
    @ApiOperation("delete")
    public R delete(@RequestBody Integer[] ids) {
        userBankService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
